'use strict';
module.exports = {
	/**
	 * 批量删除或批量作废卡密
	 */
	main: async (event) => {
		let { data = {}, userInfo, util, filterResponse, originalParam } = event;
		let { customUtil, uniID, config, pubFun, vk, db, _ } = util;
		let { uid, type, lists } = data;
		let res = { code: 0, msg: "" };
		// 业务逻辑开始-----------------------------------------------------------
		if (type == "delete") {
			let batchRunRes = await vk.pubfn.batchRun({
				// 主执行函数
				main: async (item, index) => {
					await vk.pubfn.sleep((Math.floor(Math.random() * (3 - 0)) + 0) * 100);
					const batchdel = await db.collection('a_cdkey').doc(item._id).remove()
					return {code: 0,index}
				},
				// 最大并发量，如果设置为1，则会按顺序执行
				concurrency: 100,
				// 数据源，这些数据会依次跑一遍main函数
				data: lists
			});
		}
		
		if (type == "destroy") {
			let batchRunRes = await vk.pubfn.batchRun({
				// 主执行函数
				main: async (item, index) => {
					await vk.pubfn.sleep((Math.floor(Math.random() * (3 - 0)) + 0) * 100);
					const batchdel = await db.collection('a_cdkey').doc(item._id).update({
						state: 4
					})
					return {code: 0,index}
				},
				// 最大并发量，如果设置为1，则会按顺序执行
				concurrency: 100,
				// 数据源，这些数据会依次跑一遍main函数
				data: lists
			});
		}



		// 业务逻辑结束-----------------------------------------------------------
		return res;
	}
}
